package com.wave.service;

import com.alibaba.fastjson.JSONObject;
import com.wave.entity.Info;
import com.wave.entity.LAF;
import com.wave.mapper.LAFMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LAFService {

    @Autowired
    private LAFMapper lafMapper;

    public int createLAF (LAF laf) {
        lafMapper.createLAFPara(laf);
        return lafMapper.createLAFData(laf);
    }

    public int alterLAF (LAF laf){
        if (laf.getLafGoodsDetail() != null){
            lafMapper.alterLAFData(laf);
        }
        return lafMapper.alterLAFPara(laf);
    }

    public int alterLAFState (int lafId, String state) {
        return lafMapper.alterLAFState(lafId, state);
    }

    public List<LAF> getLAFList(int type, int pageStart, int pageSize){
        String typeStr = Integer.toString(type);
        return lafMapper.getList(typeStr, pageStart, pageSize);
    }

    public JSONObject list(String type, String lafAuthorName, String lafTitle, int pageNum, int pageSize) {
        int pageStart = (pageNum - 1) * pageSize; //加载起始
        JSONObject lafList = new JSONObject();
        List<LAF> list = lafMapper.list(type, lafAuthorName, lafTitle, pageStart, pageSize);
        int total = lafMapper.countLaf(type, lafAuthorName, lafTitle);
        lafList.put("lafList", list);
        lafList.put("total", total);
        return lafList;
    }

    public int countLaf(String type, String lafAuthorName, String lafTitle) {
        return lafMapper.countLaf(type, lafAuthorName, lafTitle);
    }
    public int countLafUser() {
        return lafMapper.countLafUser();
    }
    public int countLafState(String state) {
        return lafMapper.countLafState(state);
    }

    public List<LAF> getMyLAF(String lafAuthor){
        return lafMapper.getMyLAF(lafAuthor);
    }

    public List<LAF> searchLAFTitle(String lafTitle){
        return lafMapper.searchLAFTitle(lafTitle);
    }

    public LAF getLAFDetail(Integer lafId){
        return lafMapper.getLAFDetail(lafId);
    }

    public String getState(int id){
        return lafMapper.getState(id);
    }

    public List<LAF> getIndexLAF(){
        return lafMapper.getIndexLAF();
    }
}
